#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>

#include "config.h"

static int should_query = 0;
static char package_name[25];

int main(int argc, char *argv[]) {
	int c;
	while (1) {
		static struct option long_options[] = {
			{"version", no_argument, 0, 'v'},
			{"help", no_argument, 0, 'h'},
			{"query", required_argument, 0, 'q'},
			{0, 0, 0, 0}
		};

		int option_index = 0;
		c = getopt_long(argc, argv, "vhq:", long_options, &option_index);
		
		if (c == -1) 
			break;
		
		switch (c) {
			case 0:
				if (long_options[option_index].flag != 0)
					break;
				printf("Unknown option: %s.\n", long_options[option_index].name);
				break;
			case 'v':
				printf("%s %s\n", PACKAGE, VERSION);
				break;
			case 'h':
				printf("%s\n--version, -v    print version information\n--help, -h    print help information\n--query, -q    search package repositories\n", PACKAGE);
				break;
			case 'q':
				should_query = 1;
				strncpy(package_name, optarg, sizeof(package_name));
				break;
			default:
				return 0;
		}
	}

	if (should_query == 1) {
		printf ("We will search all configured package repositories for %s.\n", package_name);
	}

	return 0;
}
